package com.mcx.modules.proto;

import com.mcx.modules.common.IProto;
import com.mcx.modules.common.MMO_DataStream;

import java.io.*;
import java.util.*;

/**
 * 服务器返回金币更新消息
 */
public class RoleData_GoldChangeReturnProto implements IProto
{
    private static MMO_DataStream dataStream = new MMO_DataStream();

    @Override
    public short getProtoCode() { return 11005; }

    public Integer OldGold; //更新前金币
    public Integer CurrGold; //更新后当前金币
    public byte ChangeType; //更新方式 0=增加 1=减少
    public byte AddType; //增加的方式
    public byte ReduceType; //减少方式
    public byte GoodsType; //物品类型
    public Integer GoodsId; //物品编号

    public byte[] ToArray() {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (DataOutputStream outputStream = new DataOutputStream(out)) {
            dataStream.outputStream = outputStream;
            dataStream.WriteShort(getProtoCode());
            dataStream.WriteInt(OldGold);
            dataStream.WriteInt(CurrGold);
            dataStream.WriteByte(ChangeType);
            dataStream.WriteByte(AddType);
            dataStream.WriteByte(ReduceType);
            dataStream.WriteByte(GoodsType);
            dataStream.WriteInt(GoodsId);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return out.toByteArray();    }
    public static RoleData_GoldChangeReturnProto GetProto(byte[] buffer) {
        RoleData_GoldChangeReturnProto proto = new RoleData_GoldChangeReturnProto();
        try (DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(buffer))) {
            dataStream.inputStream = inputStream;
            proto.OldGold = dataStream.ReadInt();
            proto.CurrGold = dataStream.ReadInt();
            proto.ChangeType = (byte)dataStream.ReadByte();
            proto.AddType = (byte)dataStream.ReadByte();
            proto.ReduceType = (byte)dataStream.ReadByte();
            proto.GoodsType = (byte)dataStream.ReadByte();
            proto.GoodsId = dataStream.ReadInt();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return proto;
    }
}